package ch9sorting;

import java.util.ArrayList;
import java.util.Arrays;

public class Ex1 {
	static void merge(ArrayList<Integer> a, ArrayList<Integer> b, int m, int n) {
		int k=m+n-1;
		while (m > 0 && n > 0) {
			int x = a.get(m-1);
			int y = b.get(n-1);
			if (x > y) {
				a.set(k, x);
				m--;
			}
			else {
				a.set(k, y);
				n--;
			}
			k--;
		}
		
		if (n > 0) {
			for (k=0; k<n; k++) {
				a.set(k, b.get(k));
			}
		}
		
	}
	
	public static void main(String ...strings) {
		Integer[] aArr = new Integer [] {2,4,6,8, null, null, null};
		ArrayList<Integer> a = new ArrayList<>(Arrays.asList(aArr));
		ArrayList<Integer> b = new ArrayList<>(Arrays.asList(new Integer [] {1,3,5}));
		merge(a, b, 4, b.size());
		int x=0;
	}
}
